package com.xgp.microChat.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

import static springfox.documentation.service.ApiInfo.DEFAULT_CONTACT;

@Configuration
@EnableSwagger2     //开启Swagger2的文档功能
public class SwaggerConfig {

/*    private final String version;
    private final String title;
    private final String description;
    private final String termsOfServiceUrl;
    private final String license;
    private final String licenseUrl;
    private final Contact contact;
    private final List<VendorExtension> vendorExtensions;*/

//    public static final ApiInfo DEFAULT = new ApiInfo("Api Documentation", "Api Documentation", "1.0", "urn:tos",
//            DEFAULT_CONTACT, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList<VendorExtension>());

    //配置Swagger2的Bean实例
    @Bean
    public Docket docket(Environment environment) {

        Profiles profiles = Profiles.of("dev","test");

        //获取项目的环境
        boolean flag = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(flag)
                .groupName("咸鱼")
                .select()
//                配置扫描接口的方式
                .apis(RequestHandlerSelectors.basePackage("com.xgp.microChat.controller"))
//                .paths()      过滤什么路径
                .build();
    }


    //配置apiInfo类
    private ApiInfo apiInfo() {
//        public static final Contact DEFAULT_CONTACT = new Contact("", "", "");
/*  public Contact(String name, String url, String email) {
            this.name = name;
            this.url = url;
            this.email = email;
        new Contact();*/

        return new ApiInfo("微聊——为简化聊天而生",
                "纵使是咸鱼，也要成为最咸的一条！",
                "1.0",
                "https://www.cnblogs.com/xgp123/",
                new Contact("咸鱼", "https://www.cnblogs.com/xgp123/", "2043928998@qq.com"),
                "xgp",
                "https://www.cnblogs.com/xgp123/",
                new ArrayList<VendorExtension>());
    }
}
